using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Castle.ActiveRecord;
using NHibernate.Expression;

/// <summary>
/// Summary description for Template
/// </summary>
/// 
/// 
[ActiveRecord("Template")]
public class Template : ActiveRecordBase<Template>
{
    public static MatchMode Exact = MatchMode.Exact;
    public static MatchMode Anywhere = MatchMode.Anywhere;
    public static MatchMode End = MatchMode.End;
    public static MatchMode Start = MatchMode.Start;

    private int iD;

    [PrimaryKey(PrimaryKeyType.Identity)]
    public int ID
    {
        get { return iD; }
        set { iD = value; }
    }

    private int siteID;

    [Property(Unique=true)]
    public int SiteID
    {
        get { return siteID; }
        set { siteID = value; }
    }

    private String name;

    [Property]
    public String Name
    {
        get { return name; }
        set { name = value; }
    }

    private String path;
    
    [Property]
    public String Path
    {
        get { return path; }
        set { path = value; }
    }


    private bool activeFlag;

    [Property]
    public bool ActiveFlag
    {
        get { return activeFlag; }
        set { activeFlag = value; }
    }

    private DateTime createdDate;
    [Property]
    public DateTime CreatedDate
    {
        get { return createdDate; }
        set { createdDate = value; }
    }


    private DateTime updatedDate;


    [Property]
    public DateTime UpdatedDate
    {
        get { return updatedDate; }
        set { updatedDate = value; }
    }

    private int createdUserID;

    [Property]
    public int CreatedUserID
    {
        get { return createdUserID; }
        set { createdUserID = value; }
    }

    private int updatedUserID;


    [Property]
    public int UpdatedUserID
    {
        get { return updatedUserID; }
        set { updatedUserID = value; }
    }

	public Template()
	{
		//
		// TODO: Add constructor logic here
		//

        this.CreatedDate = DateTime.Now;
	}

    public Template(int site,String name,String path,bool active,int createdUser)
    {
        //this.SiteID = site;
        //this.Name = name;
        //this.Path = path;
        //this.ActiveFlag = active;
        //this.CreatedUserID = createdUser;
        //this.UpdatedUserID = createdUser;
        //this.CreatedDate = DateTime.Now;
        //this.UpdatedDate = DateTime.Now;
    }

    public static void create_template(int id, String templateName, String path)
    {
        //Template template = new Template(id, templateName, path);
        //template.Create();
    }

    public static void update_template(int id, String templateName, String path)
    {
        //Template template = Template.get_template(id);
        //template.TemplateName = templateName;
        //template.Path = path;
        //template.Update();
    }

    public static void delete_template(int id)
    {
        //Template template = Template.get_template(id);
        //template.Delete();
    }

    public static Template get_template(int id)
    {
        return FindByPrimaryKey(id);
    }

    public static Template[] get_all_template()
    {
        return FindAll();
    }


    public static Template[] search_template(String propertyName, String textSearch, NHibernate.Expression.MatchMode mode)
    {
        DetachedCriteria criteria = DetachedCriteria.For<Template>();
        criteria.Add(Expression.InsensitiveLike(propertyName, textSearch, mode));
        return FindAll(criteria, Template.Asc("ID"));
    }

    public static Template[] get_template_and_sort(String propertyName, String order)
    {
        DetachedCriteria avgWeight = DetachedCriteria.For<Template>();
        if (order == "ASC")
            return FindAll(avgWeight, Asc(propertyName));
        return FindAll(avgWeight, Desc(propertyName));
    }
}
